package com.tianqu.tms.www.statistics.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.taglib.MenuBean;
import com.tianqu.tms.core.taglib.MenuDigester;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.common.controller.MenuController;

/**
 * 统计管理
 * 
 * @author hejian
 *
 */
public class StatisticsController extends TmsAction {

	private Logger logger = Logger.getLogger(StatisticsController.class);

	private static String WWW_DEFAULT_FUNC_ID = "S001";
	public static final String TMSINFO_MESSAGE = "TmsInfoMessage";

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {

		MenuDigester navigationDigester = new MenuDigester();

		MenuBean navigationVO = navigationDigester
				.digest(servlet.getServletContext().getRealPath("/WEB-INF/conf/tms-statistics-menu.xml"));
		request.setAttribute(TmsConstants.MENU_VO_KEY, navigationVO);

		String funcId = request.getParameter("funcId");

		String menu = "StatisticsHome";
		if (funcId == null) {
			funcId = WWW_DEFAULT_FUNC_ID;
		}
		if (!funcId.equals(WWW_DEFAULT_FUNC_ID)) {
			menu = "Menu" + funcId;
		}
		request.setAttribute("funcId", funcId);

		uc.clear();

		MenuController controller = new MenuController();
		controller.execute(uc);

		request.setAttribute(TMSINFO_MESSAGE, uc.getAttribute(TMSINFO_MESSAGE));
		logger.debug(this.getClass().getName() + "#doAction was completed.");

		return mapping.findForward(menu);
	}
}
